home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cuj0593.zip / 1105104A < prev    next >
Text File  |  1993-03-09  |  586b  |  23 lines

  1. /* stack.h: Macros for a stack -
  2.  *
  3.  *   A simple-minded stack mechanism. The user's
  4.  *   program must define the following in the scope
  5.  *   where they are used:
  6.  *
  7.  *   MAXSTACK            The dimension of the stack
  8.  *   size_t stkptr_ = 0; The stack pointer
  9.  *   T stk_[MAXSTACK];   The stack: an array of type T
  10.  *
  11.  *   Execution aborts if the stack overflows or
  12.  *   underflows.
  13.  */
  14.  
  15. #include <assert.h>
  16.  
  17. /* Stack operations: */
  18. #define PUSH(x) \
  19.   (assert(stkptr_ < MAXSTACK), stk_[stkptr_++] = (x))
  20. #define POP() \
  21.   (assert(stkptr_ > 0), stk_[--stkptr_])
  22.  
  23.